#include "Shield.h"
#include "global.h"
#include "Tank1.h"

void Shield::destroy()
{
	this->getParent()->removeChild(this, true);
	global_tank0god=false;
}

Shield::Shield()
{
	 CCArray *animFrames=new CCArray();
	CCSpriteFrame* pFrame0 = CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("shield0.png");
	animFrames->addObject(pFrame0);
	CCSpriteFrame* pFrame1 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("shield1.png");
	animFrames->addObject(pFrame1);
	
	CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames,0.1f);
	this->initWithSpriteFrame((CCSpriteFrame *)animFrames->objectAtIndex(0));
	animFrames->release();

	CCFiniteTimeAction* action1=CCAnimate::create(animation);
	this->runAction(CCSequence::create(CCRepeat::create(action1, 10),

	CCCallFunc::create(this, callfunc_selector(Shield::destroy)),NULL));
}

void TankBegin::destroy()
{
	Tank * tank;
	CCPoint the=this->getPosition();
	
	switch (type)
	{
	case 1: 
		tank = new  Tank1(the.x, the.y);tank->autorelease();// the.x - 13, the.y - 13);
		//MyMain.instance.tanks.add(tank.the);
		global_instance->map->addChild(tank);
		map_tankArr->addObject(tank);
		break;
	case 2: 
		tank = new Tank2(the.x, the.y);tank->autorelease();// the.x - 12, the.y - 14);
		global_instance->map->addChild(tank);
		map_tankArr->addObject(tank);
		break;
	case 3: 
		tank =new Tank3(the.x, the.y);tank->autorelease();// - 13, the.y - 13);
		global_instance->map->addChild(tank);
		map_tankArr->addObject(tank);
		break;

	}
	this->getParent()->removeChild(this, true);
}

TankBegin::TankBegin(float x,float y,int vtype)
{
	type=vtype;
	global_tank1num++;
	 CCArray *animFrames=new CCArray();
	
	CCSpriteFrame* pFrame0 = CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("tankbegin0_0.png");
	animFrames->addObject(pFrame0);
	CCSpriteFrame* pFrame1 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("tankbegin0_1.png");
	animFrames->addObject(pFrame1);
	CCSpriteFrame* pFrame2 = CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("tankbegin0_2.png");
	animFrames->addObject(pFrame2);
	CCSpriteFrame* pFrame3 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("tankbegin0_3.png");
	animFrames->addObject(pFrame3);
	CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames,0.1f);
	this->initWithSpriteFrame((CCSpriteFrame *)animFrames->objectAtIndex(0));animFrames->release();
	

	this->setPosition(ccp(x,y));
	CCFiniteTimeAction* action1=CCAnimate::create(animation);
	//CCRepeat::a
	this->runAction(CCSequence::create(action1,

		CCCallFunc::create(this, callfunc_selector(TankBegin::destroy)),NULL));


}

